package com.zl_huang.example.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zl_huang.example.model.vo.TestVO;

public class TestUtils {
	public static void main(String[] args){
		Map<Integer , Integer> map = new HashMap<Integer , Integer>();
		map.put(1, 10);
		map.put(2, 15);
		map.put(3, 15);
		System.out.println(checkSubjectMatchCountWithScore(8 , 100 , map));
	}
	public static boolean checkSubjectMatchCountWithScore(Integer totalTestCount , double totalScore , Map<Integer , Integer> examTestTypeScoreMap){
		double totalScoreMatch = 0.0;
		for(Integer key : examTestTypeScoreMap.keySet()){
			switch(key){
			case 1:
				//默认单选题取一半
			totalScoreMatch += (totalTestCount/2)*examTestTypeScoreMap.get(key);
			break;
			case 2:case 3:
				//多选题和不定项各取总题数的1/4
			totalScoreMatch += (totalTestCount/4)*examTestTypeScoreMap.get(key);
			break;
			default :
			totalScoreMatch +=0;
			break;				
			}
		}
		if(totalScoreMatch == totalScore){
			return true;
		}else{
		    return false;
		}
		
	}
	public static Map<Integer , Integer> getTestCountByEachTestType(Integer totalTestCount , Map<Integer , Integer> examTestTypeScoreMap){
		Map<Integer , Integer>  map = new HashMap<Integer , Integer>();
		for(Integer key : examTestTypeScoreMap.keySet()){
			switch(key){
			case 1:
			//默认单选题取一半
				map.put(key, totalTestCount/2);
				break;
			//多选题和不定项各取总题数的1/4
			case 2:
				map.put(key, totalTestCount/4);
				break;
			case 3:
				map.put(key, totalTestCount/4);
				break;
			default :				
				break;				
			}
		}
		return map;
	}
	public static List<TestVO> getRandomTestList(Integer count , List<TestVO> testList){
		 Map<Integer , String> map = new HashMap<Integer , String>();  
		 List<TestVO> testVOList = new ArrayList<TestVO>();  
		if(testList.size() <= count){
			 return testList;       			
		}else{
			 while(map.size() < count){  
	                int random = (int) (Math.random() * testList.size());  
	                if (!map.containsKey(random)) {  
	                    map.put(random, "");  
	                    System.out.println(random+"==========="+testList.get(random));  
	                    testVOList.add(testList.get(random));  
	                }  
	            }  
			 return testVOList;
		}
		
	}

}
